package cn.littlehx.myweb.common;

import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 全局异常处理
 */
@ControllerAdvice(annotations = {RestController.class, Controller.class})
//表示返回json数据
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {
    /**
     * 进行异常处理
     * @return
     */
    //表示处理所有异常,后期会进行修改
    @ExceptionHandler(Exception.class)
    public R exceptionHandler(@NotNull Exception ex){
        log.error("出现异常"+ex.getMessage());
        return new R(false,null,ex.getMessage());
    }
}
